//index.js
//获取应用实例
var app = getApp()
import APIURL from '../../const/APIURL'
import STUDENT from '../../API/STUDENT'
Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    img: '',
    guid: '',
    student: null,
    issearchdisplay:'hidden',
    opaticy:0,
    students:null
  },
  onShow: function () {
  var that=this;
    this.setData({ student: null })
    var data={page:1};
    STUDENT.GetLatestStudents(data).then(function(d){

      console.log(d);
      that.setData({ students: d.data })
    });
  }
  ,
  //事件处理函数
  bindViewTap: function () {
    wx.switchTab({
      url: '../logs/logs'
    })
  },
  onLoad: function () {
    console.log('onLoad')
    var that = this
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function (userInfo) {
      //更新数据
      that.setData({
        userInfo: userInfo
      })
    })


  },
  showsearch:function(){
  var that=this;
  if (this.data.issearchdisplay =='hidden')
  {
    that.setData({
      issearchdisplay:'visible',
      opaticy:1
    });
  }else{
    that.setData({
      issearchdisplay:'hidden',
      opaticy:0
    });
  }
  },  
  scancode: function () {
    var that = this
    this.setData({ student: null })
    wx.scanCode({
      success: function (res) {
        console.log(res)
        STUDENT.GetStudent(res.result).then(function (d) {

          wx.showToast({
            title: "扫描成功！",
          })
          console.log(d)
          that.setData({ student: d.data })
          console.log(that.data.student)
        })

      },
      fail: function (res) { },
      complete: function (res) { },
    })

  }
})
